package com.lz.repository.fsh.impl;

import java.util.List;

import javax.annotation.Resource;

import com.lz.entity.Customer;
import com.lz.entity.Employee;
import com.lz.repository.fsh.InsuranceSheetDao;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.lz.entity.Car;
import com.lz.entity.InsuranceSheet;

@Repository
public class InsuranceImpl extends HibernateDaoSupport implements InsuranceSheetDao {
	
	 @Resource(name="sessionFactory")
	    public void setSessionFacotry(SessionFactory sessionFacotry) {
	        super.setSessionFactory(sessionFacotry);

	    }
	 //查询车险单所有数据
	@Override
	public List<InsuranceSheet> getAlllist(Session session) {
		Query query = session.createQuery("from InsuranceSheet");
		return query.list();
	}

	@Override
	public List<Car> getList(Session session) {
		Query query = session.createQuery("from Car");
		List list = query.list();
		return list;
	}
	
	
	//添加车险单数据
	@Override
	public Integer addInsuranceSheet(Session session, InsuranceSheet insuranceSheet) {
		Integer save = (Integer)session.save(insuranceSheet);
		
		return save;
	}
   //添加客户
	@Override
	public Integer addCustomer(Session session, Customer customer) {
		Integer save = (Integer)session.save(customer);
		return save;
	}
//添加员工
	@Override
	public Integer addEmployee(Session session, Employee employee) {
		Integer save = (Integer)session.save(employee);
		return save;
	}
//条件查询
	@Override
	public List<InsuranceSheet> selectInsuranceSheet(Query query) {

	 	return query.list();
	}
    //查询总条数
	@Override
	public Integer rowsInsuranceSheet(Query query) {
		//BigInteger list = (BigInteger) query.uniqueResult();
        List list= query.list();
		return list.size();
	}
    //删除数据
	@Override
	public Integer deleteInsuranceSheet(Session session, InsuranceSheet insuranceSheet) {
	 	session.delete(insuranceSheet);
	 	Integer i=1;
	 	return i;
	}
    //获取车险单最大值
	@Override
	public Integer getMaxPrimaryKey() {
	 	Session session=getSessionFactory().openSession();
		Object o = session.createQuery("select max(insuranceSheetNo) from InsuranceSheet").uniqueResult();
		session.close();
		return (Integer) o;
	}

	//添加汽车
	@Override
	public Integer addCar(Session session, Car car) {
		Integer save = (Integer)session.save(car);
		return save;
	}

}
